package com.hzlj.position.config.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fz.common.base.converter.QueryWrapperConverterPlus;
import com.fz.common.base.converter.RemoveWrapperPlus;
import com.fz.common.base.dto.DeleteCommonDTO;
import com.fz.common.base.dto.PageParamDTO;
import com.fz.common.base.dto.QueryPageResultDTO;
import com.hzlj.position.config.common.dto.operatorActivation.OperatorActivationQueryParamDTO;
import com.hzlj.position.config.common.dto.operatorActivation.OperatorActivationQueryResultDTO;
import com.hzlj.position.config.common.model.OperatorActivation;
import com.hzlj.position.config.mapper.OperatorActivationMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定位-运营商开通(OperatorActivation)表操作类
 *
 * @author lifh
 * @date 2023-08-10 17:28:24
 */
@Repository
public class OperatorActivationDao extends ServiceImpl<OperatorActivationMapper, OperatorActivation> {
    @Resource
    private OperatorActivationMapper operatorActivationMapper;


    public boolean existsBySjh(String sjh) {
        LambdaQueryWrapper<OperatorActivation> queryWrapper = new QueryWrapper<OperatorActivation>().lambda()
                .eq(OperatorActivation::getSjh, sjh);
        return this.getOne(queryWrapper) != null;
    }


    public OperatorActivationQueryResultDTO getOperatorActivationBySjh(String sjh) {
        return QueryWrapperConverterPlus.of(operatorActivationMapper)
                .selectOne(OperatorActivationQueryResultDTO.class, null, null, q ->
                        q.eq(OperatorActivation::getSjh, sjh));
    }

    /**
     * 修改数据
     *
     * @param dto 实例对象
     * @return 实例对象
     */
    public boolean updateOperatorActivation(OperatorActivation dto) {
        LambdaQueryWrapper<OperatorActivation> queryWrapper = new QueryWrapper<OperatorActivation>().lambda()
                .eq(OperatorActivation::getId, dto.getId());
        return this.update(dto, queryWrapper);
    }

    /**
     * 删除数据
     *
     * @param dto 实例对象
     * @return 是否成功
     */
    public boolean deleteOperatorActivation(DeleteCommonDTO<String> dto) {
        return RemoveWrapperPlus.remove(this, dto);
    }

    /**
     * 查询列表：不分页
     *
     * @param dto 查询条件
     * @return 对象列表
     */
    public List<OperatorActivationQueryResultDTO> listOperatorActivation(OperatorActivationQueryParamDTO dto) {
        return QueryWrapperConverterPlus.of(operatorActivationMapper)
                .list(OperatorActivationQueryResultDTO.class, dto);
    }

    /**
     * 查询列表：分页
     *
     * @param dto  查询条件
     * @param page 分页信息
     * @return 对象列表
     */
    public QueryPageResultDTO<OperatorActivationQueryResultDTO> pageOperatorActivation(OperatorActivationQueryParamDTO dto, PageParamDTO page) {
        return QueryWrapperConverterPlus.of(operatorActivationMapper)
                .page(OperatorActivationQueryResultDTO.class, dto, page);
    }

}

